import { request } from '@umijs/max';

// 定义API返回的用户信息类型
export interface CurrentUser {
  id: string;
  name: string;
  avatar?: string;
  role: 'super_admin' | 'product_admin' | 'order_admin';
  access: string[];
}

// 定义菜单项类型
export interface MenuItem {
  path: string;
  name: string;
  icon?: string;
  component?: string;
  routes?: MenuItem[];
  access?: string;
}

// 获取当前用户信息
export async function getCurrentUser(): Promise<CurrentUser> {
  // 这里使用mock数据，实际项目中应该调用真实的API
  return Promise.resolve({
    id: '1',
    name: 'Admin',
    avatar: 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
    role: 'super_admin',
    access: ['super_admin'],
  });
}

// 获取菜单配置
export async function getMenuData(): Promise<MenuItem[]> {
  // 这里使用mock数据，实际项目中应该调用真实的API
  return Promise.resolve([
    {
      path: '/Products',
      name: '商品管理',
      icon: 'ShoppingOutlined',
      access: 'canAccessProducts',
      children: [
        {
          path: '/Products/List',
          name: '商品列表',
          component: './Products/List',
        },
        {
          path: '/Products/Detail',
          name: '商品详情',
          component: './Products/Detail',
          hideInMenu: true,
        },
      ],
    },
    {
      path: '/Orders',
      name: '订单管理',
      icon: 'HomeOutlined',
      access: 'canAccessOrders',
      children: [
        {
          path: '/Orders/List',
          name: '订单列表',
          component: './Orders/List',
        },
        {
          path: '/Orders/Detail',
          name: '订单详情',
          component: './Orders/Detail',
          hideInMenu: true,
        },
      ],
    },
  ]);
}